/*
 * frmOE.java
 *
 * Created on 9. März 2008, 12:09
 */

package com.googlecode.oskis.admin;
import com.googlecode.oskis.library.db.DBQuery;
import com.googlecode.oskis.library.db.ComboBoxEintrag;
import com.googlecode.oskis.library.db.ComboBoxFiller;
import com.googlecode.oskis.library.db.SQLErrorDialog;
import com.googlecode.oskis.library.date.NOW;
import java.sql.*;
import javax.swing.JOptionPane;

/**
 *
 * @author  thomas
 */
public class frmOE extends javax.swing.JFrame {
    
    
    private Connection db;
    
    /** Creates new form frmOE */
    public frmOE(Connection db) {
        initComponents();
        this.db=db;
        ComboBoxFiller cbf=new ComboBoxFiller(db);
        NOW now=new NOW();
        cbf.fill(cmbEinrichtung,"select einrichtung,name from xeinrichtung where "+now.getDBRepresentation()+" between datf and datt");
    }
    
    
    private void fillTable() {
        /* Wenn die Combobox noch gefüllt wird, wird auch ein ACtionEvent ausgelöst, daher 
         * prüfen, ob die Box nicht noch leer ist, ansonsten nullpointerexception
         */
        if (cmbEinrichtung.getSelectedIndex()<0) {
            return;
        }
        String einrichtung=((ComboBoxEintrag)cmbEinrichtung.getSelectedItem()).getKey();
        String SQL="select oe,bezeichnung,datf,datt" +
                "   from xoe" +
                "   where einrichtung='"+einrichtung+"'";
        DBQuery q=new DBQuery(db,SQL);
        if (q.executeQuery()) {
            tblOE.setModel(q.getTableModel());
        } else {
            JOptionPane.showMessageDialog(this,q.getSQLError());
        }
    }
    
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        lblEinrichtung = new javax.swing.JLabel();
        lblOE = new javax.swing.JLabel();
        lblBezeichnung = new javax.swing.JLabel();
        lblPOE = new javax.swing.JLabel();
        lblFOE = new javax.swing.JLabel();
        lblStation = new javax.swing.JLabel();
        lblAmbulanz = new javax.swing.JLabel();
        lblDatf = new javax.swing.JLabel();
        lblDatt = new javax.swing.JLabel();
        cmbEinrichtung = new javax.swing.JComboBox();
        txtOE = new javax.swing.JTextField();
        txtBezeichnung = new javax.swing.JTextField();
        chkPOE = new javax.swing.JCheckBox();
        chkFOE = new javax.swing.JCheckBox();
        chkStation = new javax.swing.JCheckBox();
        chkAmbulanz = new javax.swing.JCheckBox();
        txtDatf = new javax.swing.JTextField();
        txtDatt = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblOE = new javax.swing.JTable();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        lblEinrichtung.setText("Einrichtung");

        lblOE.setText("OE");

        lblBezeichnung.setText("Bezeichnung");

        lblPOE.setText("Pflegerische OE");

        lblFOE.setText("Fachliche OE");

        lblStation.setText("Station / Bettenführend");

        lblAmbulanz.setText("Ambulanz");

        lblDatf.setText("Gültig von");

        lblDatt.setText("Gültig bis");

        cmbEinrichtung.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        cmbEinrichtung.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmbEinrichtungActionPerformed(evt);
            }
        });

        jButton1.setText("Neu");

        jButton2.setText("Ändern");

        jButton3.setText("Löschen");

        tblOE.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(tblOE);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblPOE)
                            .addComponent(lblFOE)
                            .addComponent(lblStation)
                            .addComponent(lblAmbulanz)
                            .addComponent(lblDatf)
                            .addComponent(lblDatt)
                            .addComponent(lblBezeichnung)
                            .addComponent(lblEinrichtung)
                            .addComponent(lblOE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(chkFOE)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(chkAmbulanz)
                                    .addComponent(chkPOE)
                                    .addComponent(chkStation))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(txtDatt, javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(txtDatf, javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(txtBezeichnung, javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(txtOE, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 195, Short.MAX_VALUE)
                                .addComponent(cmbEinrichtung, javax.swing.GroupLayout.Alignment.LEADING, 0, 264, Short.MAX_VALUE))))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jButton1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton3))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 412, Short.MAX_VALUE)
                        .addGap(1, 1, 1)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblEinrichtung)
                    .addComponent(cmbEinrichtung, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblOE)
                    .addComponent(txtOE, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblBezeichnung)
                    .addComponent(txtBezeichnung, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblPOE)
                    .addComponent(chkPOE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblFOE)
                    .addComponent(chkFOE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblStation)
                    .addComponent(chkStation))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(lblAmbulanz)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(lblDatf))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(chkAmbulanz)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtDatf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblDatt)
                    .addComponent(txtDatt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(jButton2)
                    .addComponent(jButton3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 403, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(12, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void cmbEinrichtungActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbEinrichtungActionPerformed
        fillTable();
    }//GEN-LAST:event_cmbEinrichtungActionPerformed
    

    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JCheckBox chkAmbulanz;
    private javax.swing.JCheckBox chkFOE;
    private javax.swing.JCheckBox chkPOE;
    private javax.swing.JCheckBox chkStation;
    private javax.swing.JComboBox cmbEinrichtung;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel lblAmbulanz;
    private javax.swing.JLabel lblBezeichnung;
    private javax.swing.JLabel lblDatf;
    private javax.swing.JLabel lblDatt;
    private javax.swing.JLabel lblEinrichtung;
    private javax.swing.JLabel lblFOE;
    private javax.swing.JLabel lblOE;
    private javax.swing.JLabel lblPOE;
    private javax.swing.JLabel lblStation;
    private javax.swing.JTable tblOE;
    private javax.swing.JTextField txtBezeichnung;
    private javax.swing.JTextField txtDatf;
    private javax.swing.JTextField txtDatt;
    private javax.swing.JTextField txtOE;
    // End of variables declaration//GEN-END:variables
    
}
